home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / SciAn / src / examples / exampleSTF.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  2KB  |  80 lines

  1. /*exampleSTF.c
  2.   Example program to write an STF file
  3.  
  4.   Compile 
  5.  
  6.   cc exampleSTF.c -lm -o exampleSTF
  7.  
  8.   Eric Pepke
  9. */
  10.  
  11. #include <stdio.h>
  12. #include <math.h>
  13.  
  14. #define XSIZE 50
  15. #define YSIZE 50
  16. #define ZSIZE 50
  17.  
  18. main()
  19. {
  20.     int i, j, k;
  21.     FILE *outFile;
  22.     int dimSizes[3];
  23.     float array[XSIZE][YSIZE][ZSIZE];    /*Data array*/
  24.  
  25.     /*Fill array*/
  26.     for (i = 0; i < XSIZE; ++i)
  27.     {
  28.     for (j = 0; j < YSIZE; ++j)
  29.     {
  30.         for (k = 0; k < ZSIZE; ++k)
  31.         {
  32.         array[i][j][k] =  sin(((double) i) / XSIZE * 6.0)
  33.                 + sin(((double) j) / YSIZE * 7.0)
  34.                 + sin(((double) k) / ZSIZE * 8.0);
  35.         }
  36.     }
  37.     }
  38.  
  39.     /*Open the file*/
  40.     outFile = fopen("example.stf", "w");
  41.     if (outFile)
  42.     {
  43.     /*Print out the name, rank, dimensions, bounds*/
  44.     fprintf(outFile, "NAME field\n");
  45.     fprintf(outFile, "RANK 3\n");
  46.     fprintf(outFile, "DIMENSIONS %d %d %d\n", XSIZE, YSIZE, ZSIZE);
  47.     fprintf(outFile, "BOUNDS %g %g %g %g %g %g\n",
  48.               0.0, (float) XSIZE - 1,
  49.               0.0, (float) YSIZE - 1,
  50.               0.0, (float) ZSIZE - 1);
  51.     
  52.     /*It will be scalar data, in row order*/
  53.     fprintf(outFile, "SCALAR\n");
  54.     fprintf(outFile, "ORDER ROW\n");
  55.  
  56.     /*Emit the data*/
  57.     fprintf(outFile, "DATA\n");
  58.     for (i = 0; i < XSIZE; ++i)
  59.     {
  60.         for (j = 0; j < YSIZE; ++j)
  61.         {
  62.         for (k = 0; k < ZSIZE; ++k)
  63.         {
  64.             fprintf(outFile, "%g ", array[i][j][k]);
  65.         }
  66.  
  67.         /*Put in a newline every row just to make it easier to
  68.           read by a person*/
  69.         fprintf(outFile, "\n");
  70.         }
  71.     }
  72.  
  73.     fclose(outFile);
  74.     }
  75.     else
  76.     {
  77.     perror("example.stf");
  78.     }
  79. }
  80.